package com.xiaoyang.ssyx.product.api;


import com.xiaoyang.ssyx.model.product.Category;
import com.xiaoyang.ssyx.model.product.SkuInfo;
import com.xiaoyang.ssyx.product.service.CategoryService;
import com.xiaoyang.ssyx.product.service.SkuInfoService;
import com.xiaoyang.ssyx.vo.product.SkuInfoVo;
import com.xiaoyang.ssyx.vo.product.SkuStockLockVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @AUTHOR XiaoYang
 * @DATE 2023/6/17-13:22
 * @DESCRIPTION TODO
 */
@RestController
@RequestMapping("/api/product")
//@SuppressWarnings({"unchecked", "rawtypes"})
public class ProductInnerController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private SkuInfoService skuInfoService;

    //根据分类id获取分类信息
    @GetMapping("inner/getCategory/{categoryId}")
    public Category getCategory(@PathVariable("categoryId") Long categoryId){
        Category category = categoryService.getById(categoryId);
        return category;
    }


    //根据skuid获取sku信息
    @GetMapping("inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId){
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return skuInfo;
    }

    //根据skuId列表得到sku信息列表
    @PostMapping("inner/findSkuInfoList")
    public List<SkuInfo> findSkuInfoList(@RequestBody List<Long> skuIdList){
        return skuInfoService.findSkuInfoList(skuIdList);
    }

    //根据关键字匹配sku列表
    @GetMapping("inner/findSkuInfoByKeyword/{keyword}")
    public List<SkuInfo> findSkuInfoByKeyword(@PathVariable("keyword") String keyword){
        return skuInfoService.findSkuInfoByKeyword(keyword);
    }

    //根据分类id获取分类列表
    @PostMapping("inner/findCategoryList")
    public List<Category> findCategoryList(@RequestBody List<Long> categoryIdList){
        return categoryService.listByIds(categoryIdList);
    }

    //获取所有分类(home)
    @GetMapping("inner/findAllCategoryList")
    public List<Category> findAllCategoryList() {
        return categoryService.list();
    }

    //获取新人专享商品(home)
    @GetMapping("inner/findNewPersonSkuInfoList")
    public List<SkuInfo> findNewPersonSkuInfoList() {
        List<SkuInfo> list = skuInfoService.findNewPersonList();
        return list;
    }

    //根据skuId获取sku信息(home)
    @GetMapping("inner/getSkuInfoVo/{skuId}")
    public SkuInfoVo getSkuInfoVo(@PathVariable Long skuId){
        return skuInfoService.getSkuInfoVo(skuId);
    }

    //验证和锁定库存(order)
    @ApiOperation(value = "锁定库存")
    @PostMapping("inner/checkAndLock/{orderNo}")
    public Boolean checkAndLock(@RequestBody List<SkuStockLockVo> skuStockLockVoList,
                                @PathVariable String orderNo){
        return skuInfoService.checkAndLock(skuStockLockVoList,orderNo);
    }

}
